<template>
	<view class="toView">
		<view class="header">
			<image src="../../../static/img/quickly/assessment/question_1@2x.png"></image>
			<view class="information">
				<view class="top">
					<view>会员：{{userInfo.realName || ''}}</view>
					<view>年龄：{{userInfo.age || ''}}岁</view>
					<view>性别：{{userInfo.sex == 1 ? '男' : userInfo.sex == 2 ? '女' : '未知'}}</view>
				</view>
				<view class="bottom">
					<view>签发人：{{questionData.sources == 3 ? questionData.healthName : questionData.realName}}</view>
					<view>填写日期：{{questionData.questionTime}}</view>
				</view>
			</view>
		</view>
		<view class="two"></view>
		<view class="three"></view>
		
		<uni-collapse :accordion="accordion">
		    <!-- <uni-collapse-item v-for="(item,index) in QuestionnaireStencil" :key="index" :title="index>3 ? item.name+ '(必选项)': item.name" :name="index" showAnimation :titleStyle="{'background':'#36AB7C','color':'#fff'}"> -->
		    <uni-collapse-item v-for="(item,index) in QuestionnaireStencil" :key="index" :title="item.name" :name="index" showAnimation :titleStyle="{'background':'#36AB7C','color':'#fff'}">
		        <div v-if="index == 0">
		            <div v-for="(a,aindex) in item && item.data" class="item">
		                <p class="que"><i>{{aindex+1}}</i>{{a.name}}：</p>
						<checkbox-group>
							<label  v-for="(b,bi) in a.data" :key="bi">
								<checkbox :value="b.questionNo" color="#007aff" :checked="data[b.questionNo]" :disabled="true">{{b.questionTitle}}</checkbox>
							</label>
						</checkbox-group>
		            </div>
		        </div>
		        <div v-else-if="index == 1 || index ==2">
					<div class="item">
						<checkbox-group>
							<label v-for="(a,aindex) in item.data" :key="aindex">
								<checkbox color="#007aff" :value="a.questionNo" :checked="data[a.questionNo]" :disabled="true">{{a.questionTitle}}</checkbox>
							</label>
						</checkbox-group>
					</div>
		        </div>
		        <div v-else>
					<div v-for="(a,aindex) in item.data">
						<div v-if="a.name" :class="a.className">
							<div class="item">
								<p class="que"><i>{{aindex+1}}</i>{{a.name}}：</p>
								<checkbox-group>
									<label v-for="(b,bindex) in a.data" :key="bindex">
										<checkbox color="#007aff" :value="b.questionNo" :checked="data[b.questionNo]" :disabled="true">{{b.questionTitle}}</checkbox>
									</label>
								</checkbox-group>
							</div>
						</div>
						<div :class="a.className" v-else>
							<div class="item" v-show="a.show">
								<p class="que" v-show="a.show"><i>{{aindex+1}}</i>{{a.questionTitle}}：<span v-if="a.questionTitle != '常吃早餐' && a.questionTitle != '常吃夜宵'">(必选)</span></p>
								<radio-group @change="radioChange">
									<label v-for="(b, bi) in a.data" :key="bi">
										<view>
											<radio :value="JSON.stringify({'questionNo':b.questionNo,'answerOption':b.answerOption})" :checked="data[b.questionNo] == b.answerOption"  :disabled="true"/>
										</view>
										<view>{{b.answerTxt}}</view>
									</label>
								</radio-group>
							</div>
						</div>
					</div>
		        </div>
		    </uni-collapse-item>
		</uni-collapse>
	</view>
</template>
<script>
	import {filterData2,age} from '@/static/js/filter.js'
	export default {
		data (){
			return {
				userInfo:{},
				QuestionnaireStencil:[],
				accordion: true,
				data:[],
				questionData:{}
			}
		},
		onLoad(options){
			const _this = this;
			_this.$api.getQuestionnaireStencil({type:1}).then(res=>{
				_this.filterArr(res.data.result)
			})
			_this.$api.findByUserId(options.userId).then((res) => {
				_this.userInfo = res.data.result;
				_this.userInfo.age = age('',_this.userInfo.birthday)
			})
			_this.editid = options.id
			_this.userName = options.userName;
			_this.userId = options.userId;
			_this.$api.Questionnairefind(options.userId,options.questionNumber,{type:1}).then((res)=>{
				_this.resultData = res.data.result.questionnaireAnswerVoList
				_this.questionData = res.data.result
				res.data.result && res.data.result.questionnaireAnswerVoList && res.data.result.questionnaireAnswerVoList.map((e)=>{
					_this.$set(_this.data,[e.questionNo],e.answerOption)
					_this.questionTime = res.data.result.questionTime
					_this.id = res.data.result.id
					_this.start_date = filterData2(res.data.result.createTime)
				})
			})
		},
		methods:{
			age,
			// 问卷整合
			filterArr(e){
				let _this = this;
				let arr = []
				e.map((ev,i)=>{
					let hasIndex = arr.findIndex((av,ai)=>{ return av.questionNo == ev.questionNo})
					if(hasIndex > -1){
						ev.checked = false
						ev.disabled = _this.questionStatus == 2?true:false
						arr[hasIndex].data.push(ev)
					}else{
						ev.checked = false
						ev.disabled = _this.questionStatus == 2?true:false
						arr.push({data:[ev],questionNo:ev.questionNo,questionTitle:ev.questionTitle,show:true})
					}
				})
				// 
				// 家族病史
				var gxy = {name:'高血压病',data:arr.filter((e,i)=>{ return e.questionTitle.indexOf('高血压病') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 高血压
				var xzyc = {name:'血脂异常',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('血脂异常') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 血脂异常	
				var gzss = {name:'骨质疏松',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('骨质疏松') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 骨质疏松	
				var ga = {name:'肝癌',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('肝癌') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 肝癌	
				var rxa = {name:'乳腺癌',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('乳腺癌') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 乳腺癌	
				var tnb = {name:'糖尿病',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('糖尿病') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 糖尿病	
				var fpz = {name:'肥胖症',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('肥胖症') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 肥胖症	
				var aezhmb = {name:'阿尔茨海默病',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('阿尔茨海默病') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 阿尔茨海默病	
				var wa = {name:'胃癌',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('胃癌') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 胃癌	
				var gja = {name:'宫颈癌',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('宫颈癌') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 宫颈癌	
				var gxb = {name:'冠心病',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('冠心病') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 冠心病	
				var ncz = {name:'脑卒中',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('脑卒中') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 脑卒中	
				var fa = {name:'肺癌',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('肺癌') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 肺癌	
				var qlxa = {name:'前列腺癌',data:arr.filter((e,i)=>{return e.questionTitle.indexOf('前列腺癌') > -1 &&  e.questionTitle.indexOf('本人') == -1})} // 前列腺癌
				gxy.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('高血压病',''); return a})
				xzyc.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('血脂异常',''); return a})
				gzss.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('骨质疏松',''); return a})
				ga.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('肝癌',''); return a})
				rxa.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('乳腺癌',''); return a})
				tnb.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('糖尿病',''); return a})
				fpz.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('肥胖症',''); return a})
				aezhmb.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('阿尔茨海默病',''); return a})
				wa.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('胃癌',''); return a})
				gja.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('宫颈癌',''); return a})
				gxb.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('冠心病',''); return a})
				ncz.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('脑卒中',''); return a})
				fa.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('肺癌',''); return a})
				qlxa.data.map((a)=>{ a.questionTitle = a.questionTitle.replace('前列腺癌',''); return a})
				const jzbs = {name:'家族病史',data:[gxy,xzyc,gzss,ga,rxa,tnb,fpz,aezhmb,wa,gja,gxb,ncz,fa,qlxa]}
			
				// 患病情况
				const hbqk = {name:'患病情况',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('本人') > -1  
				})}
				hbqk.data = hbqk.data.map((a,aindex)=>{
					a.questionTitle = a.questionTitle.replace('本人','')
					return a
				}).filter(b=>{
					if(this.sex == '男'){
						return b.questionTitle != '宫颈癌' && b.questionTitle != '乳腺癌'
					}else{
						return b.questionTitle != '前列腺癌'
					}
				})
				// 既往情况
				const jwqk = {name:'既往情况',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('油烟') > -1  ||
					e.questionTitle.indexOf('粉烟尘') > -1  || 
					e.questionTitle.indexOf('毒物致癌物') > -1  || 
					e.questionTitle.indexOf('高温') > -1  || 
					e.questionTitle.indexOf('低温') > -1  || 
					e.questionTitle.indexOf('辐射') > -1  || 
					e.questionTitle.indexOf('噪音或震动') > -1  
				})}
				// 饮食习惯
				var ysxg = {name:'饮食习惯',data:arr.filter((e,i)=>{ 
					return  e.questionTitle.indexOf('常吃早餐') > -1 ||
					e.questionTitle.indexOf('常吃夜宵') > -1
				})}
				this.ysxg = ysxg;
			
				var ysxgA1 = arr.filter((a)=>{
					return a.questionTitle.indexOf('喜好清淡') > -1 || 
						   a.questionTitle.indexOf('喜好咸') > -1 || 
						   a.questionTitle.indexOf('喜好甜') > -1 || 
						   a.questionTitle.indexOf('喜好生') > -1 || 
						   a.questionTitle.indexOf('喜好冷') > -1 || 
						   a.questionTitle.indexOf('喜好硬') > -1 || 
						   a.questionTitle.indexOf('喜好热烫') > -1 || 
						   a.questionTitle.indexOf('喜好高油脂') > -1 || 
						   a.questionTitle.indexOf('喜好烟熏') > -1 || 
						   a.questionTitle.indexOf('喜好辛辣') > -1
				})
				var ysxgA1data = [{name:'您的饮食口味',data:ysxgA1.map((a)=>{
					a.questionTitle = a.questionTitle.replace('饮食喜好','')
					return a
				})}]
				var ysxgA2 = arr.filter((a)=>{
					return a.questionTitle.indexOf('过') > -1 || a.questionTitle.indexOf('吃饭时喝水') > -1
				})
				var ysxgA3 = arr.filter((a)=>{
					return a.questionTitle.indexOf('油炸食品') > -1 || 
						   a.questionTitle.indexOf('甜点') > -1 || 
						   a.questionTitle.indexOf('吃零食') > -1 || 
						   a.questionTitle.indexOf('经常吃快餐') > -1 || 
						   a.questionTitle.indexOf('喝粥') > -1
				})
				var ysxgA2data = [{name:'您目前饮食的不良习惯',data:ysxgA2}]
				var ysxgA3data = [{name:'您的饮食偏好',data:ysxgA3,className:'long'}]
			
				ysxg.data = ysxg.data.concat(ysxgA2data,ysxgA1data,ysxgA3data)
				// console.log(ysxg)
				// 个人膳食摄入
				const grss = {name:'个人膳食摄入',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('每天食量') > -1 ||
					e.questionTitle.indexOf('水每天饮用量') > -1 
				})}
				this.grss = grss;
			
				// 运动锻炼
				const yddl = {name:'运动锻炼',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('工作时间') > -1 ||
					e.questionTitle.indexOf('静坐时间') > -1 ||
					e.questionTitle.indexOf('运动锻炼') > -1 
				})}
				this.yddl = yddl;
				// 吸烟情况
				const xyxg = {name:'吸烟情况',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('吸烟') > -1 || e.questionTitle.indexOf('平均每天几支') > -1 
				})}
				this.xyxgArr = xyxg
				// 饮酒情况
				const yjxg = {name:'饮酒情况',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('饮酒') > -1 || e.questionTitle.indexOf('平均每天几两') > -1 
				})}
				this.yjqkArr = yjxg
			
				// 心理健康
				const xljk = {name:'心理健康',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('困扰') > -1 || e.questionTitle.indexOf('情绪') > -1 || e.questionTitle.indexOf('压力') > -1 
				})}
				this.xljk = xljk;
				// 睡眠健康
				const smjk = {name:'睡眠健康',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('睡眠') > -1 
				})}
				this.smjk = smjk;
			
				// 其他
				const qt = {name:'其他',data:arr.filter((e,i)=>{ 
					return e.questionTitle.indexOf('皮质激素服用') > -1 
				})}
				this.qt = qt;
				this.QuestionnaireStencil.push(jzbs,hbqk,jwqk,ysxg,grss,yddl,xyxg,yjxg,xljk,smjk,qt)
				// console.log(this.QuestionnaireStencil)
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import "@/static/css/quickly/tcm/toView.scss" ;
	.que{font-size: 26upx;color: #333;background: #fff;}
	.que i{font-style: normal;display: inline-block;padding:2upx 12upx;background: #3CBE8A;color: #fff;line-height: 1;border-radius:2upx;font-size: 16upx;margin-right: 8upx;}
	.item{
		padding:20upx;
		background: #fff;
		.uni-label-pointer,uni-radio-group{
			display: flex;
			flex-wrap: wrap;
			font-size: 22upx;
			uni-checkbox,.uni-label-pointer{
				width:50%;
				margin-top: 24upx;
			}
		}
		uni-checkbox-group{
			display: flex;
			flex-wrap: wrap;
			font-size: 22upx;
			uni-label{
				width:50%;
				margin-top: 12upx;
				uni-checkbox{
					width: 100% !important;
					
				}
			}
		}
	}
	.uni-collapse {
		// margin-top: 130upx;
		/deep/ .uni-checkbox-input-checked,/deep/ .uni-radio-input-checked{
			background: #3CBE8A !important;
			color: #fff !important;
			&:before{
				font-size: 36upx !important;
			}
		}
		/deep/ uni-checkbox .uni-checkbox-input{
			border-radius: 8upx;
			width: 28rpx;
			height: 28rpx;
		}
		/deep/ uni-radio .uni-radio-input{
			border-radius: 8upx;
			width: 28rpx;
			height: 28rpx;
		}
	}
	
	
	/deep/ .uni-collapse-cell--hide{
		height: 78upx !important;
	}
	/deep/ .uni-collapse-cell__title{
		background: #ECFBF6 !important;
		height: 78upx !important;
		border-bottom: 1rpx solid #fff;
	}
	/deep/ .uni-collapse-cell__title-text{
		padding-left: 30upx;
		span{
			color: #38CB97;
		}
		&::before{
			content: '';
			position: absolute;
			width: 10upx;
			height: 30upx;
			background: #38CB97;
			left: 20upx;
			top: 32%;
			border-radius: 4upx;
		}
	}
	/deep/ .uni-icons{
		color: #999999 !important;
	}
</style>
